<template>
  <div>
    <el-table
      :data="roleList"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      default-expand-all
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
    <el-table-column type='index' label="角色序号">
</el-table-column>
      <el-table-column prop="id" label="角色编号" >
      </el-table-column>
      <el-table-column prop="rolename" label="角色名称" >
      </el-table-column>
      <el-table-column label="状态">
        <template v-slot="scoped">
          <div>
            <el-button type="success" v-if="scoped.row.status == 1"
              >启用</el-button
            >
            <el-button type="info" v-else>禁用</el-button>
          </div>
        </template>
      </el-table-column>
       <el-table-column  label="操作">
        <template v-slot="scoped">
          <div>
            <el-button @click="edit(scoped.row.id)">编辑</el-button>
            <el-button @click="del(scoped.row.id)">删除</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import {roleDel} from "../../../request/api.js"
import {sucessAlert,warningAlert} from "../../../utils/alert.js"
export default {
  props: [],
  components: {},
  data() {
    return {
    };
  },
  computed: {
    ...mapGetters({
         roleList:"role/list"
    }),
  },
  methods: {
    ...mapActions({
             asyncRoleList:"role/asynclist"
    }),
    del(id){
     this.$confirm('此操作将永久删除该文件，是否继续？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type:"warning"
        }).then(() =>
         {
                //点击成功
          roleDel({
                  id:id
                }).then(res=>{
                    if(res.data.code == 200){
                // 成功的提示窗
                sucessAlert(res.data.msg),
                // 刷新列表数据
                this.asyncRoleList()
            }else{
                // 失败的提示窗
                warningAlert(res.data.msg)
            }
                })
          }).catch(()=> {
            // 如果走的catch说明点的是取消
             warningAlert("已取消删除")
          
          });
    },
    edit(id){
      this.$emit("edit",id)
    }
  },
  mounted() {
      this.asyncRoleList()
  },
};
</script>
<style scoped>
</style>